<?php
/**
 * 一些高危操作，比如清表等
 */

class DangerController extends TrendAdminAbstract
{
    protected $_passwd = '1q2w3e';
    
    /**
     * 整站初始化 - 清库、清磁盘
     */
    public function initSite()
    {
        /* 接收参数 */
        $passwd = $this->input->get('pwd');
        
        /* 权限校验 */
        if ($passwd != $this->_passwd) {
            echo 'No permission!';
            exit;
        }
        
        /* 统一的清空条件 */
        $where_mysql = null;
        $where_mongo = array();
        
        /* 清空 mysql - 案件分类表 */
        Archive_Model_Category::instance()->delete($where_mysql);
        
        /* 清空 mysql - 部门表 */
        Archive_Model_Department::instance()->delete($where_mysql);
        
        
        /* 清空 mongodb - 行动表 */
        Archive_Model_Card::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 案件删除二次确认队列表 */
        Archive_Model_Confirm::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 案件表 */
        Archive_Model_Content::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 档案案件操作历史表 */
        Archive_Model_History::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 案件相关文件下载历史表 */
        Archive_Model_History_Download::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 案件操作日志表 */
        Archive_Model_Log::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 档案案件分享表 */
        Archive_Model_Share::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 上传附件表 */
        Attachment_Model_Content::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 音视频文件打点记录表 */
        Attachment_Model_Content_Dot::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 上传附件临时缓存表 */
        Attachment_Model_Content_Temp::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 用户虚拟目录表 */
        Attachment_Model_Folder::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 文件（夹）重名处理表 */
        Attachment_Model_Juna::instance()->deleteByWhere($where_mongo);

        /* 清空 mongodb - 上传过程中切片缓存池表 */
        Task_Model_Block_Buffer::instance()->deleteByWhere($where_mongo);

        /* 清空 mongodb - 上传任务表 */
        Task_Model_Order::instance()->deleteByWhere($where_mongo);

        /* 清空 mongodb - 标签库表 */
        Trend_Model_Label::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 标签关联关系表 */
        Trend_Model_Label_Rel::instance()->deleteByWhere($where_mongo);
        
        /* 清空 mongodb - 通用通知表 */
        Trend_Model_Notify::instance()->deleteByWhere($where_mongo);
        
        
        /* 清理磁盘 */
        exec('rm -rf /home/project/archive/upload/*');
        exec('mkdir /home/project/archive/upload/tmp');
        exec('mkdir /home/project/archive/upload/tmps');
        exec('chmod -R 777 /home/project/archive/upload/');
        
        echo '初始化完成！';
    }
}

// End ^ Native EOL ^ UTF-8